# -*- coding: utf-8 -*-
import random


def bucket_sort(li, n=100, max_num=10000):
    buc = [[] for i in range(n)]  # 创建桶
    for val in li:
        i = min(val // (max_num // n), n - 1)
        buc[i].append(val)
        for j in range(len(buc[i]) - 1, 0, -1):
            if buc[i][j] < buc[i][j - 1]:
                buc[i][j], buc[i][j - 1] = buc[i][j - 1], buc[i][j]
            else:
                break
    result = []
    for rel in buc:
        result.extend(rel)
    return  result

li = [random.randint(0,10000) for i in range(100000)]
# print(li)
li = bucket_sort(li)
print(li)